package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.BaseData;
import com.cskaoyan.bean.bo.CommentParam;
import com.cskaoyan.bean.pojo.MallComment;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.CommentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: harveyliu
 * @description: 用来处理商品评论的请求
 * @time: 2021/7/9 20:10
 */
@RestController
@RequestMapping("admin/comment")
public class CommentController {

    @Autowired
    CommentService commentService;

    /**
     * @Author harvey
     * @description: 用来得到所有的评论响应给页面
     * @Date 2021/7/9 20:11
     * url: http://182.92.235.201:8083/admin/comment/list?page=1&limit=20&userId=1&valueId=2&sort=add_time&order=desc
     */
    @RequestMapping("list")
    @RequiresPermissions("admin:comment:list")
    public BaseRespVo queryCommentByConditions(CommentParam commentParam) {
        BaseData<MallComment> mallCommentBaseData = commentService.queryCommentsByConditions(commentParam);
        return BaseRespVo.ok(mallCommentBaseData);
    }

    /**
     * @Author harvey
     * @description: 用来实现评论的逻辑删除
     * @Date 2021/7/9 20:31
     * url: http://182.92.235.201:8083/admin/comment/delete
     */
    @RequestMapping("delete")
    @RequiresPermissions("admin:comment:delete")
    public BaseRespVo deleteCommentById(@RequestBody MallComment mallComment) {
        commentService.deleteCommentById(mallComment);
        return BaseRespVo.ok();
    }
}
